/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package reyes.mysite.struts;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

/**
 *
 * @author reyesyang
 */
public class PostNewBlogActionForm extends org.apache.struts.action.ActionForm {

    private String blogTitle;
    private String blogCategory;
    private String blogPrivacy;
    private String blogSummary;
    private String blogContent;


    public String getBlogTitle() {
        return blogTitle;
    }

    public void setBlogTitle(String blogTitle) {
        this.blogTitle = blogTitle;
    }

    public String getBlogCategory() {
        return blogCategory;
    }

    public void setBlogCategory(String blogCategory) {
        this.blogCategory = blogCategory;
    }

    public String getBlogPrivacy() {
        return this.blogPrivacy;
    }

    public void setBlogPrivacy(String blogPrivacy) {
        this.blogPrivacy = blogPrivacy;
    }

    public String getBlogSummary() {
        return this.blogSummary;
    }

    public void setBlogSummary(String blogSummary) {
        this.blogSummary = blogSummary;
    }

    public String getBlogContent() {
        return blogContent;
    }

    public void setBlogContent(String blogContent) {
        this.blogContent = blogContent;
    }
    
    public PostNewBlogActionForm() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param request The HTTP Request we are processing.
     * @return
     */
    @Override
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        ActionErrors errors = new ActionErrors();
        if (blogTitle == null || blogTitle.length() < 1) {
            errors.add("blogTitle", new ActionMessage("errors.nullOrEmpty"));
            // TODO: add 'error.name.required' key to your resources
        }
        if(blogCategory.equals("not-chose")) {
            errors.add("blogCategory", new ActionMessage("errors.notChose"));
        }
        if(blogPrivacy.equals("not-chose")) {
            errors.add("blogPrivacy", new ActionMessage("errors.notChose"));
        }
        if(blogSummary == null || blogSummary.length() < 1) {
            errors.add("blogSummary", new ActionMessage("errors.nullOrEmpty"));
        }
        if(blogContent == null || blogContent.length() < 1) {
            errors.add("blogContent", new ActionMessage("errors.nullOrEmpty"));
        }
        return errors;
    }
}
